package algorithm;

import java.util.ArrayList;
import java.util.List;

public class leetcode_0077 {
    public List<List<Integer>> combine(int n, int k) {
        List<List<Integer>> list=new ArrayList<>();
        List<Integer> path=new ArrayList<>();
        backtracking(list,path,n,k,1,1);
        return list;
    }
    public void backtracking(List<List<Integer>> list,List<Integer> path,int n,int k,int begin,int num){
        if(num>k){
            list.add(new ArrayList<>(path));
            return;
        }
        if(begin>n){

            return;
        }
        for(int i=begin;i<=n;++i){
            path.add(i);
            backtracking(list,path,n,k,i+1,num+1);
            path.remove(path.size()-1);
        }
    }
}
